package testApplets;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import processing.core.PApplet;

public class ImportExportTest extends PApplet {
	public void setup() {
		float[] myvalues = new float[100000000];
		for (int i = 0; i < myvalues.length; i++) {
			myvalues[i] = i;
		}
		
		//saveValuesFloat(myvalues);
	}
	 
	public void saveFloatArray(float[] source,String fileName) {
		try {
			FileOutputStream fos3 = new FileOutputStream(fileName);
			DataOutputStream dos3 = new DataOutputStream(new BufferedOutputStream(fos3));
			int n = 0;
			int i;
			for (int j = 0; j < source.length; j++) {
			dos3.writeFloat(source[j]);
			}
			dos3.flush();
			dos3.close();
			fos3.flush();
			fos3.close();
		}
		catch (FileNotFoundException ex) {
			System.out.println("FileNotFoundException : " + ex);
		} catch (IOException ioe) {
		}
		println("saved");
	}
	public float[] readFloatArray(String fileName){
		String path=this.selectInput();
		File file = new File(path);
		FileInputStream fin;
		float[] values=null;
		try {
			fin = new FileInputStream(path);
			BufferedInputStream bin = new BufferedInputStream(fin);
			DataInputStream din = new DataInputStream(bin);
			int count = (int) (file.length() / 4);
			values= new float[count];
			for (int i = 0; i < count; i++) {
			    try {
					values[i] = din.readFloat();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		} catch (FileNotFoundException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		return values;
	}
}
